﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EmoneyWeiXinDAL;
using EmoneyWeiXinEntity;
using EmoneyWeiXinCommon;

namespace EmoneyWeiXinBLL
{
    public class weixinUserBLL
    {
        public List<StockDoctorloguserEntity> getStockdoctordUser(string weixinid)
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.getStockdoctordUser(weixinid);
        }

        //获取48小时活跃的分组用户
        public List<StockDoctorloguserEntity> GetGroupUserAt48HHy(string weixinid, string groupId)
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.GetGroupUserAt48HHy(weixinid,groupId);
        }

        public List<weixinUserEntity> getWeixinUser1()
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.getWeixinUser1();
        }
        public List<weixinUserEntity> getWeixinUser1(int userid)
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.getWeixinUser1(userid);
        }

        public weixinUserEntity getWeixinUserByID(int weixinid)
        {
            weixinUserDAL dal = new weixinUserDAL();
            var data = dal.getWeixinUser1();
            if (data != null && data.Count > 0)
            {
                var obj = data.Where(p => p.id == weixinid).ToList();
                if (obj != null && obj.Count > 0)
                {
                    return obj[0];
                }
            }
            return new weixinUserEntity();
        }

        public List<weixinUserEntity> GetWeixinUser(string id, int pageindex = 0, int pagecount = 0)
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.GetWeixinUser(id, pageindex, pagecount);
        }

        public int GetTableNameCount(string tablename)
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.GetTableNameCount(tablename);
        }

        public int weixinUpdate(weixinUserEntity wetity)
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.weixinUpdate(wetity);
        }

        public int weixindel(string id)
        {
            weixinUserDAL dal = new weixinUserDAL();
            return dal.weixindel(id);
        }

        public weixinUserEntity GetWeixinUserFromCache(string weixinId)
        {
            MemcachedTools1 mmtols = new MemcachedTools1();
            string getWXUserKey = StringTools.ChangeRealKey("weixinUser", weixinId);
            object wxObject = mmtols.Get(getWXUserKey);
            weixinUserEntity tempWxInfo = null;
            if (wxObject != null)
            {
                tempWxInfo = JsonTools.ToObject<weixinUserEntity>(wxObject.ToString());
            }
            return tempWxInfo;
        }
    }
}
